package com.qyi.activemq.topic.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQMessage;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.jms.Session;

/**
 * @author luqi
 * @Date 2021/3/11 10:09
 * @Description TODO
 */
@Service
@Slf4j
public class MqConsumerService {

    /**
     * concurrency为复数时，会执行多次
     *
     * @param msg
     * @param message
     * @param session
     * @throws Exception
     */
    @JmsListener(destination = "t1-topic", containerFactory = "jmsListenerContainerTopic", concurrency = "1")
    public void receiveStringTopic1(String msg, ActiveMQMessage message, Session session) throws Exception {
        log.info("consumer topic1:{}", msg);
    }

    /**
     * @param msg
     * @param message
     * @param session
     * @throws Exception
     */
    @JmsListener(destination = "t1-topic", containerFactory = "jmsListenerContainerTopic", concurrency = "1")
    public void receiveStringTopic2(String msg, ActiveMQMessage message, Session session) throws Exception {
        log.info("consumer topic2:{}", msg);
    }
}
